package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.example.administrator.myapplication.adapter.Myadapter;
import com.example.administrator.myapplication.bean.Weather;
import com.example.administrator.myapplication.util.GetJsonDataUtil;
import com.google.gson.Gson;

import java.util.List;

import javax.security.auth.login.LoginException;

public class MainActivity extends AppCompatActivity {

    private static final String TAG ="MainActivity";
    private ListView weatherListview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    private void initView(){

        weatherListview = (ListView) findViewById(R.id.weather_listview);

    }
    private void initData(){
        String jsonData=new GetJsonDataUtil().getJson(MainActivity.this,"data.json");
        Log.e(TAG,"initData:"+jsonData);
        Gson gson=new Gson();
        //映射关系
        Weather weathers=gson.fromJson(jsonData,Weather.class);
        String todayTemperature=weathers.getResult().getToday().getTemperature();
        Toast.makeText(MainActivity.this,todayTemperature, Toast.LENGTH_SHORT).show();
        String skwind=weathers.getResult().getSk().getWind_strength();
        Toast.makeText(MainActivity.this,skwind, Toast.LENGTH_SHORT).show();

        List<Weather.ResultBean.FutureBean> futurebeans=weathers.getResult().getFuture();
        Log.e(TAG,"initData:"+ futurebeans.get(0).getTemperature()+"");
        weatherListview.setAdapter(new Myadapter(MainActivity.this,futurebeans));
    }
    private void initEvent(){

    }
}
